Create a class called Invoice that a hardware store in OOP C++ - RZ Mentor
Create a class called ‘Invoice’ that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four data members—a part number (type string), a part description (type string), a quantity of the item being purchased (type float), and a price per item (type float). Your class should have a constructor that initializes the four data members. Provide a set and a get function for each data member. In addition, provide a member function named getInvoiceAmount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as an int value. If the quantity is not positive, it should be set to 0. If the price per item is not positive, it should be set to 0. Write a test program that demonstrates the class Invoice’s capabilities.
This program creates an Invoice
object with a part number, part description, quantity, and price per item. It then prints the part number, part description, quantity, and price per item using the get_part_number
, get_part_description
, get_quantity
, and get_price_per_item
methods. It then updates the quantity and price per item using the set_quantity
and set_price_per_item
methods, and prints the updated values. Finally, it prints the invoice amount using the get_invoice_amount
method.
1 Comments
nice
ReplyDeleteIf You have any doubts, please let me know.